package com.example.projectcode.controller.Teacher;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.projectcode.model.Chapter;
import com.example.projectcode.model.Choice;
import com.example.projectcode.model.Comprehensive;
import com.example.projectcode.model.Subject;
import com.example.projectcode.result.Result;
import com.example.projectcode.service.*;
import com.example.projectcode.vo.ChoiceVo;
import com.example.projectcode.vo.ComprehensiveVo;
import com.example.projectcode.vo.UpdateChoiceVo;
import com.example.projectcode.vo.UpdateComprehensiveVo;
import com.sun.org.apache.bcel.internal.generic.ARETURN;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "题库管理接口")
@RestController
@RequestMapping("/teacher/questionManage")
public class QuestionManageController {

    @Autowired
    private SubjectService subjectService;

    @Autowired
    private ChapterService chapterService;

    @Autowired
    private TestPointService testPointService;

    @Autowired
    private ChoiceService choiceService;

    @Autowired
    private ComprehensiveService comprehensiveService;


    @ApiOperation("展示科目")
    @GetMapping(value = "displaySUbject")
    public Result displaySubject(){
        return Result.ok(subjectService.selectAllSubject());
    }

    @ApiOperation("展示科目对应章节")
    @GetMapping(value = "displayChapter/{Subid}")
    public Result displayChapter(@PathVariable Integer Subid){
        return Result.ok(chapterService.selectAllChapterBySubid(Subid));
    }

    @ApiOperation("展示章节对应考点")
    @GetMapping(value = "displaytestPoint/{Chapid}")
    public Result displayTestPoint(@PathVariable Integer Chapid){
        return Result.ok(testPointService.selectAllTestPointByChapid(Chapid));
    }

    /* -----------------------------------------选择题操作接口--------------------------------------------*/

    @ApiOperation("根据考点Id展示对应选择题")
    @GetMapping(value = "/displayChoiceBytestpointId/{testPointId}/{page}/{size}")
    public Result displayChoiceBytestpointId(@PathVariable Integer testPointId,
                                             @PathVariable long page,
                                             @PathVariable long size){
        Page<Choice> choicePage = new Page<>(page,size);
        IPage<Choice> iPage = choiceService.page(choicePage,
                new QueryWrapper<Choice>().eq("Testpointid",testPointId));

        return Result.ok(iPage);

    }


    @ApiOperation("根据考点名字添加选择题")
    @PostMapping(value = "/insertChoice")
    public  Result insertChoice(@RequestBody ChoiceVo choiceVo){
        int result = choiceService.insertChoice(choiceVo);

        if (result>0){
            return Result.ok().message("添加成功");
        }else {
            return Result.fail().message("添加失败");
        }
    }

    @ApiOperation("根据选择题id删除选择题")
    @GetMapping(value = "/deleteChoice/{choiceId}")
    public Result  deleteChoice(@PathVariable Integer choiceId){
        int result = choiceService.deleteCHoiceById(choiceId);
        if (result>0){
            return Result.ok().message("删除成功");
        }else {
            return Result.fail().message("删除失败");
        }
    }

    @ApiOperation("修改题目信息")
    @PostMapping(value = "/updateChoiceById")
    public Result updateChoice(@RequestBody UpdateChoiceVo updateChoiceVo){
        int result = choiceService.updateChoiceById(updateChoiceVo);
        if (result>0){
            return Result.ok().message("修改成功");
        }else {
            return Result.fail().message("修改失败");
        }
    }


    /* ----------------------------综合题操作接口-------------------------------------------*/


    @ApiOperation("根据考点Id展示对应综合题")
    @GetMapping(value = "/displayComprehensiveBytestpointId/{testPointId}/{page}/{size}")
    public Result displayComprehensiveBytestpointId(@PathVariable Integer testPointId,
                                             @PathVariable long page,
                                             @PathVariable long size){
        Page<Comprehensive> comprehensivePage = new Page<>(page,size);
        IPage<Comprehensive> iPage = comprehensiveService.page(comprehensivePage,
                new QueryWrapper<Comprehensive>().eq("Testpointid",testPointId));

        return Result.ok(iPage);

    }



    @ApiOperation("根据考点名字添加综合题")
    @PostMapping(value = "/insertComprehensive")
    public Result insertComprehensive(@RequestBody ComprehensiveVo comprehensiveVo){
        int result = comprehensiveService.insertComprehensive(comprehensiveVo);

        if (result>0){
            return Result.ok().message("添加成功");
        }else {
            return Result.fail().message("添加失败");
        }
    }


    @ApiOperation("根据综合题Id修改题目信息")
    @PostMapping(value = "/updateComprehensiveById")
    public Result updateComprehensive(@RequestBody UpdateComprehensiveVo updateComprehensiveVo){
      int result =   comprehensiveService.updateComprehensiveById(updateComprehensiveVo);
        if (result>0){
            return Result.ok().message("修改成功");
        }else {
            return Result.fail().message("修改失败");
        }
    }

    @ApiOperation("根据选择题id删除综合题")
    @GetMapping(value = "/deleteComprehensiveById/{comprehensiveId}")
    public Result  deleteComprehensiveById(@PathVariable Integer comprehensiveId){
        int result =comprehensiveService.deleteComprehensiveById(comprehensiveId);
        if (result>0){
            return Result.ok().message("删除成功");
        }else {
            return Result.fail().message("删除失败");
        }
    }







}
